
//!============================================================================
//!<Interface> Vertex|Fragment
//!----------------------------------------------------------------------------

//!<Include> StdLight.sl

struct StdPointLight {
	// Light colors
	StdLightColor Colors;
	// Light position
	vec3 Position;
	// Half vector
	vec3 HalfVector;
	// Attenuation factors
	StdLightAttenuation Attenuation;
};

// Compute positional light contribution
void ComputeLightContribution(inout StdLightColor colors, StdPointLight light, vec3 normal, vec3 eye, vec3 ec, float shiness);

//!============================================================================
//!<Source> Vertex|Fragment
//!----------------------------------------------------------------------------

//<Include> Interface

void ComputeLightContribution(inout StdLightColor colors, StdPointLight light, vec3 normal, vec3 eye, vec3 ec, float shininess)
{
	float NormalDotLightDir;
	float PowerFactor = 0.0;
	float Distance = length(light.Position.xyz - ec);
	float Attenuation = 1.0 / (light.Attenuation.Constant + (light.Attenuation.Linear * Distance) + (light.Attenuation.Quadratic * Distance * Distance));
	vec3 LightDir = normalize(light.Position.xyz);

	// Dot product between surface normal and light direction
	NormalDotLightDir = max(0.0, dot(normal, LightDir));
	
	// Contribute with ambient
	colors.Ambient += light.Colors.Ambient * Attenuation;
	// Contribute with diffuse
	colors.Diffuse += light.Colors.Diffuse * NormalDotLightDir * Attenuation;
	// Contribute with specular
	if ((NormalDotLightDir != 0.0) && (shininess != 0.0)) {
		vec3 HalfVector = normalize(LightDir + eye);
		float NormalDotLightHalf = max(0.0, dot(normal, HalfVector));
		
		colors.Specular += light.Colors.Specular * pow(NormalDotLightHalf, shininess) * Attenuation;
	}
}

//!============================================================================
//! Implementation notes
//!----------------------------------------------------------------------------
//!
//!----------------------------------------------------------------------------

